/*
 * 亿迅公司源代码，版权归亿迅公司所有。 项目名称 : bnet_process 创建日期 : Apr 30, 2009 修改历史 : 1. [Apr 30,
 * 2009]创建文件 by zhoujinhuang
 */
package cn.eshore.bnet.bpm.service;

import java.util.List;

import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;

import org.springframework.transaction.annotation.Transactional;

import cn.eshore.bnet.bpm.Constants;
import cn.eshore.bnet.bpm.dto.NodeInstanceDTO;
import cn.eshore.bnet.bpm.dto.ProcessInstanceDTO;
import cn.eshore.bnet.bpm.dto.TaskInstanceDTO;
import cn.eshore.bnet.bpm.dto.TaskResult;
import cn.eshore.bnet.bpm.dto.ext.ProcessParam;

/**
 * 流程管理接口
 * 
 * @author zhoujinhuang
 */
@WebService(name = "ProcessService", targetNamespace = Constants.BPM_NS)
@Transactional
public interface ProcessService {
    /**
     * Todo: 是否有必要加入businessKey ？ 发起流程
     * 
     * @param ProcessType
     * @param request
     * @param businessKey
     *            业务系统中的流程实例标示
     * @return 流程编号
     * @throws ProcessException
     */
    // public abstract long startProcess(String processName,
    // List<ProcessParm> variables, String businessKey)
    // throws ProcessException;
    public long startProcess(@WebParam(name = "processName")
    String processName, @WebParam(name = "processParms")
    List<ProcessParam> processParams, @WebParam(name = "businessKey")
    String businessKey) throws ProcessException;

    /**
     * 获取任务列表
     * 
     * @param actotId
     * @return 任务列表
     */
    public @WebResult(name = "taskInstanceDTOs")
    List<TaskInstanceDTO> getTaskList(@WebParam(name = "actorId")
    String actorId);

    /**
     * 获取任务参数名称
     * 
     * @param paramName
     * @return
     */
    public @WebResult(name = "processParam")
    List<ProcessParam> getTaskParams(@WebParam(name = "taskInstanceId")
    long taskInstanceId, @WebParam(name = "paramNames")
    List<String> paramNames);

    /**
     * 获取流程参数名称
     * 
     * @param paramName
     * @return
     */
    public @WebResult(name = "processParam")
    List<ProcessParam> getProcessParams(@WebParam(name = "processInstanceId")
    long processInstanceId, @WebParam(name = "paramNames")
    List<String> paramNames);

    /**
     * 获取局部流程变量
     * 
     * @param processInstanceId
     * @param tokenId
     * @param paramNames
     * @return
     */
    public @WebResult(name = "processParam")
    List<ProcessParam> getLocalParams(@WebParam(name = "tokenId")
    long tokenId, @WebParam(name = "paramNames")
    List<String> paramNames);

    /**
     * 处理任务,并推进流程
     */
    public void completeTask(TaskResult taskResult);

    /**
     * 查询流程状态
     * 
     * @param processInstanceId
     * @return 流程实例描述，包括流程经历的和当前的业务节点
     */
    public @WebResult(name = "processInstanceDTO")
    ProcessInstanceDTO getProcessInstance(@WebParam(name = "processInstanceId")
    long processInstanceId);

    /**
     * 获取流程当前节点
     * 
     * @param processInstanceId
     * @return
     */
    public @WebResult(name = "node")
    NodeInstanceDTO getCurrentNodeInstance(
            @WebParam(name = "processInstanceId")
            long processInstanceId);

    /**
     * 推进流程
     * 
     * @param processInstanceId
     */
    public void signal(long processInstanceId);

    /**
     * 更新流程变量 ??? 有必要？
     * 
     * @param processInstanceId
     */
    public void updateVar(@WebParam(name = "processInstanceId")
    long processInstanceId, @WebParam(name = "processInstanceId")
    List<ProcessParam> processParams);

    /**
     * 流程发布
     * 
     * @param processDefinitionXml
     */
    public void deploy(String processDefinitionXml);

    /**
     * 扫描指定路径，加载流程定义
     */
    public void deployAll();

    public void endProcessInstance(long processInstanceId);

    /**
     * 获取单个流程的所有流程实例
     * 
     * @param processDefinitionId
     * @return
     */
    public @WebResult(name = "ProcessInstanceDTO")
    List<ProcessInstanceDTO> findProcessInstances(
            @WebParam(name = "processDefinitionId")
            long processDefinitionId);

    /**
     * 获取单个流程的所有流程实例
     * 
     * @param processDefinitionId
     * @return
     */
    public @WebResult(name = "ProcessInstanceDTO")
    List<ProcessInstanceDTO> findProcessInstances(
            @WebParam(name = "processName")
            String processName);

    /**
     * resume token
     * 
     * @param processInstanceId
     */
    public void resumeToken(long processInstanceId);
}